//
//  ViewController.m
//  WKWebViewOC
//
//  Created by XiaoFeng on 2017/1/5.
//  Copyright © 2017年 XiaoFeng. All rights reserved.
//  QQ群: 384089763 欢迎加入
//  github链接: https://github.com/XFIOSXiaoFeng/WKWebView

#import "ViewController.h"
#import "WKWebViewController.h"
#import "WKWebViewController.h"

@interface ViewController ()
@property (nonatomic, strong) UITextField * textTF;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"登录";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.textTF = [[UITextField alloc] initWithFrame:CGRectMake(0, 120, self.view.frame.size.width, 60)];
    self.textTF.font = [UIFont systemFontOfSize:17];
    self.textTF.textColor = [UIColor blackColor];
    self.textTF.textAlignment = NSTextAlignmentCenter;
    self.textTF.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
    self.textTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.textTF.placeholder = @"请输入ip地址";
    [self.view addSubview:self.textTF];
    
    UIButton * commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    commitBtn.frame = CGRectMake(30, 220, self.view.frame.size.width - 60, 45);
    [commitBtn setTitle:@"登录" forState:UIControlStateNormal];
    [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    commitBtn.backgroundColor = [UIColor redColor];
    [commitBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
    
    UILabel * tip = [[UILabel alloc] initWithFrame:CGRectMake(30, 290, self.view.frame.size.width - 60, 200)];
    tip.textColor = [UIColor grayColor];
    tip.font = [UIFont systemFontOfSize:15];
    tip.numberOfLines = 0;
    tip.textAlignment = NSTextAlignmentCenter;
    tip.text = @"IP地址可以手动输入\n默认地址是\nhttp://testgt.caibangw.com:8880/#/home";
    [self.view addSubview:tip];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)loginAction{
    [self.view endEditing:YES];
    WKWebViewController *web = [[WKWebViewController alloc] init];
    if ([self.textTF.text isEqualToString:@""]) {
        [web loadWebURLSring:@"http://testgt.caibangw.com:8880/#/home"];
    }else{
        [web loadWebURLSring:self.textTF.text];
    }
    web.isNavHidden = YES;
    [self.navigationController pushViewController:web animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)loadingAction:(UIButton *)sender {
    WKWebViewController *web = [[WKWebViewController alloc] init];
    [web loadWebURLSring:@"http://testgt.caibangw.com:8880/#/rechargemoney"];
    [self.navigationController pushViewController:web animated:YES];
}

@end
